package com.many.backs.controller;

import com.baomidou.mybatisplus.extension.api.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestController
 * @Description TODD
 * @Author James
 * @Date 2022/7/28
 * @Version 1.0
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Value("${server.port}")
    private String port;
    @Value("${spring.redis.port}")
    private String host;

    @GetMapping("/port")
    public R port(){
        return R.ok(port+""+host);
    }

    //通过LogFactory获取Logger类的实例
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @GetMapping("log")
    public String hello(){
        logger.error("=====>error");
        logger.warn("=====>warn");
        logger.info("=====>info");
        logger.debug("=====>debug");
        logger.trace("=====>trace");
        return "SpringBoto Log";
    }

    public static void main(String[] args) {
        //模拟从前端获得的密码
        String password = "123456";
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String newPassword = bCryptPasswordEncoder.encode(password);
        System.out.println("加密的密码为: "+newPassword);
        //使用matches方法进行密码的校验
        boolean same_password_result = bCryptPasswordEncoder.matches(password,newPassword);
        //返回true
        System.out.println("加密的密码和正确密码对比结果: "+same_password_result);
        boolean other_password_result = bCryptPasswordEncoder.matches("987654",newPassword);
        //返回false
        System.out.println("加密的密码和错误的密码对比结果: " + other_password_result);
    }


}
